package client;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

import commons.User;
import commons.Message;

public class Client {
    private String serverIP = "127.0.0.1";
    private int serverPort = 55555;
    private Socket currentSocket;
    private User currentUser = new User();
    private ObjectOutputStream out;

    public Client(){
        if (!readConfig())
            System.exit(0);
        try {
            this.currentSocket = new Socket(serverIP, serverPort);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Menu menu = new Menu();
        Scanner scanner = new Scanner(System.in);
        int input;
        while (true){
            menu.printMenu();
            System.out.print("Input number what you want: ");
            try{
                switch (Integer.parseInt(scanner.nextLine())){
                    case 0: logIn(); break;
                    case 1: createAccount(); break;
                    case 2: this.currentSocket.close();System.exit(0);
                }
            } catch (NumberFormatException e){
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        /*try {

            this.out = new ObjectOutputStream(this.currentSocket.getOutputStream());
            Scanner scanner = new Scanner(System.in);
            String str;
            while (!(str = scanner.nextLine()).equals("exit")){
                Message message = new Message();
                message.setMessage(str);
                message.setSender(currentUser);
                this.out.writeObject(message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

    private boolean readConfig(){

        return true;
    }

    private boolean logIn(){
        System.out.println("Log in was done");
        return true;
    }

    private void createAccount(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Input your login: ");
        String login = scanner.nextLine();
        System.out.print("Input your password: ");
        String password = scanner.nextLine();
        User newUser = new User();
        newUser.setLogin(login);
        newUser.setPassword(password);

        System.out.println("Account was created");
    }


}
